package com.ee.chat.common.service.impl;

import com.ee.chat.common.dao.UserExpandMapper;
import com.ee.chat.common.dao.UserSetMapper;
import com.ee.chat.common.entity.UserExpand;
import com.ee.chat.common.entity.UserSet;
import com.ee.chat.common.service.IUpdateEntityService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author shane
 * @version 1.0.0
 * @Date 2021/1/26 16:30
 */
@Service
public class UpdateEntityServiceImpl implements IUpdateEntityService {
    @Resource
    UserSetMapper userSetMapper;
    @Resource
    UserExpandMapper userExpandMapper;

    @Override
    public int updateUserSet(UserSet userSet) {
        if(userSet.getId() == null){
            UserSet temp = userSetMapper.selectByUserId(userSet.getUserId());
            if(temp == null){
                return userSetMapper.insert(userSet);
            }else{
                userSet.setId(temp.getId());
                return userSetMapper.updateById(userSet);
            }
        }else{
            return userSetMapper.updateById(userSet);
        }
    }

    @Override
    public int updateUserExpand(UserExpand userExpand) throws Exception {
        if(userExpand.getId() == null){
            UserExpand temp = userExpandMapper.selectByUserId(userExpand.getUserId());
            if(temp == null){
                return userExpandMapper.insert(userExpand);
            }else{
                userExpand.setId(temp.getId());
                return userExpandMapper.updateById(userExpand);
            }
        }else{
            return userExpandMapper.updateById(userExpand);
        }
    }
}
